using Assets.Scripts.GDK;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Brick
{
	public class Utils : gdk_utils
	{
		public static RectTransform addDebugBtn(Action callback)
		{
			RectTransform rectTransform = gdk_utils.NewButton();
			Text text = gdk_utils.NewText();
			rectTransform.sizeDelta = new Vector2(80f, 80f);
			text.transform.SetParent(rectTransform);
			text.text = "DEBUG";
			text.fontSize = 20;
			rectTransform.position = gdk_utils.getSceneSize() * new Vector2(0.5f, 0.5f) - rectTransform.sizeDelta;
			Vector3 position = rectTransform.position;
			if (position.x > 360f)
			{
				RectTransform rectTransform2 = rectTransform;
				Vector3 position2 = rectTransform.position;
				rectTransform2.position = new Vector2(280f, position2.y - 80f);
			}
			rectTransform.gameObject.GetComponent<Button>().onClick.AddListener(delegate
			{
				callback();
			});
			return rectTransform;
		}

		public static double[] hypotenuse(double _long, double _angle)
		{
			double[] array = new double[2];
			double num = Math.PI / 180.0 * _angle;
			array[0] = Math.Sin(num) * _long;
			array[1] = Math.Cos(num) * _long;
			return array;
		}

		public static float TanAngle(Vector2 from, Vector2 to)
		{
			float x = to.x - from.x;
			float y = to.y - from.y;
			float num = Mathf.Atan2(y, x);
			return num * 57.29578f;
		}

		public static List<Vector2> getPosList(int length)
		{
			List<Vector2> list = new List<Vector2>();
			list.Clear();
			double num = 360 / length;
			int num2 = 0;
			for (int i = 0; i < length; i++)
			{
				double[] array = hypotenuse(148.0, num * (double)num2);
				num2++;
				float x = (float)array[0];
				float y = (float)array[1];
				list.Add(new Vector2(x, y));
			}
			return list;
		}

		public static string toLevelIndex(int index)
		{
			string text = index.ToString();
			if (text.Length == 1)
			{
				text = "00" + text;
			}
			if (text.Length == 2)
			{
				text = "0" + text;
			}
			if (text.Length == 3)
			{
			}
			return text;
		}

		public static T AddXibItem<T>(RectTransform box, string itemUrl)
		{
			GameObject gameObject = gdk_game_manager.loadPrefab(itemUrl);
			T component = gameObject.GetComponent<T>();
			gameObject.transform.SetParent(box);
			gameObject.GetComponent<RectTransform>().localPosition = new Vector3(0f, 0f, 0f);
			gameObject.GetComponent<RectTransform>().localScale = new Vector3(1f, 1f, 1f);
			return component;
		}

		public static bool ContainsVector2Model(List<Vector2Model> vector2ModelList, Vector2Model vector2Model)
		{
			for (int i = 0; i < vector2ModelList.Count; i++)
			{
				Vector2Model vector2ModelA = vector2ModelList[i];
				if (EqualsVector2Model(vector2ModelA, vector2Model))
				{
					return true;
				}
			}
			return false;
		}

		public static bool EqualsVector2Model(Vector2Model vector2ModelA, Vector2Model vector2ModelB)
		{
			return vector2ModelA.x == vector2ModelB.x && vector2ModelA.y == vector2ModelB.y;
		}
	}
}

